//
//  WebFileViewController.m
//  Epweike_Witkey
//
//  Created by epwk on 15/8/26.
//  Copyright (c) 2015年 zengxusheng. All rights reserved.
//

#import "WebFileViewController.h"

@interface WebFileViewController ()

@end

@implementation WebFileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    self.actity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [self.actity setFrame:CGRectMake(0, 0, 30, 30)];
    [self.actity setCenter:CGPointMake(ScreenWith/2, self.view.center.y)];
    [self.view addSubview:self.actity];
    [self.actity setHidesWhenStopped:YES];
    [self.actity setHidden:NO];
    [self.actity startAnimating];
    
    if (_payBool) {
        [self requestPayMoneyWithParams:@{@"orderNo":_payId}];
    }else
        [self loadWebView];
    //    self.fileUrl = @"http://img11.epweike.us/data/uploads/2014/12/03/305041932547edd481e9fb.mp3";
}


-(void)loadWebView
{
    NSURL *url = [NSURL URLWithString:self.fileUrl];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
}

- (void)webViewDidStartLoad:(UIWebView *)webView//开始加载的时候执行该方法
{
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView//加载完成的时候执行该方法。
{
    [self.actity stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
{
    [self.actity stopAnimating];
}


#pragma mark - RequestAction 充值 支付
-(void)requestPayMoneyWithParams:(NSDictionary *)pramas
{
//    [SVProgressHUD show];
    [[AFNetApiClient sharedClient] requestPayMoneyWithParams:pramas success:^(AFHTTPRequestOperation *operation , id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary *dic = responseObject;
        if ([dic[@"responseCode"] intValue] == 200) {
            _fileUrl = dic[@"responseObj"][@"payurl"];
            [self loadWebView];
        }else
        {
            [self.actity stopAnimating];
            [SVProgressHUD showErrorWithStatus:dic[@"responseMessage"]];
        }
    } failure:^(AFHTTPRequestOperation *operation , NSError *error) {
        NSLog(@"%@",error);
        [SVProgressHUD dismiss];
        [self.actity stopAnimating];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
